﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;

namespace Test_2D
{
    [Serializable]
    public class Canvas
    {
        private Size backgroundSize, size;

        private Color color;

        public Canvas(Size _size, Color _color)
        {
            size = _size;
            color = _color;

            int minwd = 1000, minhe = 700, mul = 3;  //设置画布(不是中间白色的部分)的最小宽度，最小高度，扩大倍数
            int newwd, newhe;
            //Bitmap bp = new Bitmap(cvs.Size.Width, cvs.Size.Height);

            newwd = mul * _size.Width;
            newhe = mul * _size.Height;
            if (newwd < minwd)
                newwd = minwd;
            if (newhe < minhe)
                newhe = minhe;

            backgroundSize = new Size(newwd, newhe);
            //panel2.Size = new Size(newwd, newhe);

            //Graphics g = Graphics.FromImage(bp);
            //g.Clear(cvs.Color);

            //panel2.BackgroundImage = bp;

        }
        //备用
        public Canvas(Size _backgroundSize, Size _size, Color _color)
        {
            backgroundSize = _backgroundSize;
            size = _size;
            color = _color;
        }
        //备用
        public Canvas(int _width, int _height, Color _color)
        {
            size = new Size(_width, _height);
            color = _color;
        }

        /// <summary>
        /// 获得画布中央区域的左上角与画布的左上角的偏移，以便在播放的时候修正运动元的位置
        /// </summary>
        public Point Offset
        {
            get
            {
                return new Point((size.Width - backgroundSize.Width) / 2, (size.Height - backgroundSize.Height) / 2);
            }
        }
        /// <summary>
        /// 画布白色部分大小
        /// </summary>
        public Size Size
        {
            get { return size; }
            set { size = value; }
        }
        public Color Color
        {
            get { return color; }
            set { color = value; }
        }
        /// <summary>
        /// 画布总大小
        /// </summary>
        public Size BackgroundSize
        {
            get { return backgroundSize; }
            set { backgroundSize = value; }
        }
    }
}
